<template>
  <div class="tool-bar">
    <section class="rt-box blackBox">
      <div class="arrowBottomRight" v-for="(item,index) in list" :key="item.value">
        <div class="icon-container" @click="onToggle(item.value,index)">
          <i class="icon " :class="item.icon"></i>
          <div class="icon-name">{{item.name}}</div>
        </div>
      </div>
    </section>

    <div class="pop-box" v-show="visiable" >   
      <i class="tran" :style="{ right: [style.right+'px'] }"></i>
      <!-- toolbox 工具-->
      <template v-if="name=='ToolBox'">
        <keep-alive>
          <component :toolList="toolList" :is="name" @changeToolState="changeToolState" @changeWidget="changeWidget">
          </component>
        </keep-alive>
      </template>
      <template v-else>
        <keep-alive>
          <component :is="name"  @changeMapThumbnail="changeMapThumbnail"></component>
        </keep-alive>
      </template>
    </div>

  </div>
</template>
<script>
  const list = [{
    name: '漫游',
    value: 'BasicRoam',
    icon: 'icon-roam'
  }, {
    name: '视点',
    value: 'ViewPointManage',
    icon: 'icon-viewpoint'
  }, {
    name: '图层',
    value: 'LayerTree',
    icon: 'icon-layer'
  }, {
    name: '底图',
    value: 'BaseLayerSwitcher',
    icon: 'icon-basemap'
  }, {
    name: '工具',
    value: 'ToolBox',
    icon: 'icon-tool'
  }]

  export default {
    props: {
      toolList: {
        type: Array
      },
    },
    components: {
      "BasicRoam": () => import("@/widgets/BasicRoam/index.vue"),
      "ViewPointManage": () => import("@/widgets/ViewPointManage/index.vue"),
      "LayerTree": () => import("@/widgets/LayerTree/index.vue"),
      "BaseLayerSwitcher": () => import("@/widgets/BaseLayerSwitcher/index.vue"),
      "ToolBox": () => import("@/widgets/ToolBox/index.vue"),
    },
    data() {
      return {
        list: list,
        name: "",
        visiable: false,

        style: {
          right: 50
        }
      };
    },
    mounted() {

    },
    methods: {
      changeMapThumbnail(checkedKeys){
        this.$emit("changeMapThumbnail", checkedKeys);
      },
      onToggle(key, index) {
        if (key == this.name) {
          this.visiable = !this.visiable;
          this.setAttributeEnquiryState(key);
          return
        }
        this.visiable = true;
        this.name = key;
        this.setAttributeEnquiryState(key);
        this.style.right = 380 - index * 82; 
      },
      changeWidget(o) {
        this.$emit("changeWidget", o);
      },
      changeToolState(o) {
        this.$emit("changeToolState", o);
      },
      setAttributeEnquiryState(key) {
        if (key == 'ToolBox' && this.visiable) {
          this.$store.state.attrRadio = '';
        } else {
          this.$store.state.attrRadio = 'close';
        }
      }
    },
  };
</script>
<style scoped>
  .tool-bar {
    position: absolute;
    top: 76px;
    right: 14px;
  }

  .rt-box {
    width: 438px;
    height: 46px;
    background: rgba(1, 10, 23, 0.8);
    box-shadow: 0px 2px 6px 0px rgb(0 0 0 / 50%);
    border-radius: 3px;
    padding: 6px 10px;
    box-sizing: border-box;
  }

  .pop-box {
    position: absolute;
    top: 50px;
    right: 0;
    background: rgba(1, 10, 23, 0.8);
    border-radius: 5px;
    color: #fff;
  }

  .pop-box .tran {
    content: "";
    position: absolute;
    top: -6px; 
    width: 0;
    height: 0;
    border-left: 6px solid transparent;
    border-right: 6px solid transparent;
    border-bottom: 6px solid rgba(1, 10, 23, 0.8);
  }

  .map-tool {
    display: inline-block;
    width: 48px;
    height: 48px;
    position: absolute;
    top: 120px;
    right: 12px;
    z-index: 3;
    background: rgba(0, 0, 0, 0);
    color: white;
  }

  .icon-box:hover {
    color: rgba(247, 243, 243, 0.6);
    background: rgba(247, 243, 243, 0.6);
  }

  .icon-box:hover i {
    opacity: 1;
  }

  .icon-setting {
    display: inline-block;
    width: 26px;
    height: 26px;
    background: url(../../img/tool/sys-setting.png) no-repeat;
    background-size: 100%;
    vertical-align: -4px;
  }

  .icon-fullscreen {
    display: inline-block;
    width: 16px;
    height: 16px;
    background: url(../../img/tool/sys-fullscreen.png) no-repeat;
    background-size: 100%;
    vertical-align: -3px;
  }

  .icon-box .icon-fullscreen1 {
    background: url(../../img/tool/sys-fullscreen1.png) no-repeat;
    background-size: 100%;
  }

  .anticon-setting {
    font-size: 18px;
    vertical-align: -3px;
    margin-right: 5px;
  }

  .icon {
    display: inline-block;
    width: 16px;
    height: 16px;
    overflow: hidden;
    vertical-align: sub;
  }

  .rt-box .arrowBottomRight {
    display: inline-block;
    width: 20%;
    text-align: center;
    cursor: pointer;
    position: relative;
  }

  .rt-box .arrowBottomRight:after {
    content: "";
    position: absolute;
    height: 24px;
    width: 1px;
    background: rgba(220, 223, 230, 0.37);
    right: 0;
    top: 4px;
  }

  .rt-box .arrowBottomRight:last-child:after {
    border-right: none;
    width: 0;
  }

  .rt-box .arrowBottomRightFirst:after {
    content: "";
    position: absolute;
    height: 24px;
    width: 1px;
    background: rgba(220, 223, 230, 0.37);
    right: 0;
    top: 4px;
  }

  .rt-box .arrowBottomRightSecond:after {
    content: "";
    position: absolute;
    height: 24px;
    width: 1px;
    background: rgba(220, 223, 230, 0.37);
    right: 0;
    top: 4px;
  }

  .icon-container {
    height: 30px;
    margin: 0 6px;
    border: 1px solid rgba(0, 0, 0, 0);
  }

  .icon-container:hover {
    background: none;
    border: 1px solid #1e90ff;
    border-radius: 4px;
  }

  .icon-container .icon-name {
    display: inline-block;
    line-height: 30px;
    margin-left: 4px;
    font-size: 16px;
    font-weight: 400;
    vertical-align: middle;
  }

  .blackBox .icon-container .icon-name {
    color: #ffffff;
  }

  .rt-box .icon {
    display: inline-block;
    width: 22px;
    height: 22px;
    margin: auto;
    vertical-align: middle;
  }

  .icon.icon-layer {
    background: url(../../img/tool/layer.webp) no-repeat;
    background-size: 100%;
  }

  .icon.icon-baselayer {
    background: url(../../img/tool/viewpoint.png) no-repeat;
    background-size: 100%;
  }

  .icon.icon-tool {
    background: url(../../img/tool/tool.webp) no-repeat;
    background-size: 100%;
  }

  .icon.icon-search {
    background: url(../../img/tool/search.webp) no-repeat;
    background-size: 100%;
  }

  .icon.icon-basemap {
    background: url(../../img/tool/basemap.png) no-repeat;
    background-size: 100%;
  }

  .icon.icon-viewpoint {
    background: url(../../img/tool/viewpoint.png) no-repeat;
    background-size: 100%;
  }


  .switch-title {
    display: inline-block;
    width: 85px;
    height: 30px;
    text-align: right;
  }

  .icon-roam {
    background: url(../../img/tool/roam.webp) no-repeat;
    background-size: 100%;
  }
</style>